<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const cities = [
      {
        "value": "13",
        "text": "河北省",
        "children": [
          {
            "value": "1306",
            "text": "保定市",
            "children": [
              {
                "value": "130602",
                "text": "竞秀区"
              },
              {
                "value": "130606",
                "text": "莲池区"
              },
              {
                "value": "130607",
                "text": "满城区"
              },
              {
                "value": "130608",
                "text": "清苑区"
              },
              {
                "value": "130609",
                "text": "徐水区"
              },
              {
                "value": "130628",
                "text": "高阳县"
              },
              {
                "value": "130636",
                "text": "顺平县"
              }
            ]
          }
        ]
      }
    ]
    const arr = JSON.parse(JSON.stringify(cities))
    let data = null
    let str = ''
    // 定义一个函数传入value来获取是在哪个地方，例如输入130628返回结果就是【河北省，保定市，高阳县】
    function placeName(number) {
      function fun(arr) {
        for (const key in arr) {
          if (arr[key].value == number) {
            return data = arr[key].text
          } else if (!arr[key].children && arr[key].value == number) {
            return data = arr[key].text
          }
          if (arr[key].children) str += arr[key].text

          fun(arr[key].children)

        }
      }
      fun(arr)
    }
    placeName(130606)
    console.log(str + data)

  </script>
</body>

</html>